package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.bean.Merchant;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface MerchantMapper extends BaseMapper<Merchant> {

    // 根据商户名和密码查询商户
    @Select("SELECT * FROM merchant WHERE m_name=#{username} AND m_password = #{password}")
    Merchant SelectMerchant(@Param("username") String username, @Param("password") String password);

    //根据商户名查询商户
    @Select("SELECT * FROM merchant WHERE m_name=#{name}")
    Merchant SelectMerchantByName(@Param("name") String name);

    /**
     * 查询商家id的最大值
     *
     * @return
     */
    @Select("SELECT MAX(m_id)FROM merchant")
    int SelectMaxMid();

    /**
     * 注册
     *
     * @param mid      商家id
     * @param name     商家名字
     * @param phone    商家手机号
     * @param password 商家密码
     * @param email    商家邮箱
     * @return
     */
    @Insert("INSERT INTO merchant(m_id,m_name,m_phone,m_password,m_email) VALUE(#{mid},#{name},#{phone},#{password},#{email});")
    public int RegisterMerchant(@Param("mid") int mid, @Param("name") String name, @Param("phone") String phone,
                                @Param("password") String password, @Param("email") String email);

    @Select("select m_name from merchant where m_id=#{mid}")
    String findMerchantName(int mid);
}
